package ml;

import java.util.List;

import parser.ParserAnnotation;
import parser.ParserPipeline;
import corpus.SentPolarityCorpus;
import corpus.WordPolarity;
import corpus.WordPolarityCorpus;
import forum.ForumPost;

public class MajorityVoting extends DataModel {

	private WordPolarityCorpus wpc;

	public MajorityVoting(String name, ParserPipeline pp, String[] labels, WordPolarityCorpus wpc) {
		super(name, pp, labels);
		this.wpc = wpc;
	}

	@Override
	public void classify(ForumPost post) throws Exception {
		ParserAnnotation pa = post.getParserAnnotation();
		for (int i = 0; i < pa.getNbrSentences(); i++) {
			List<String> tokens = pa.getTokens(i);
			List<String> poss = pa.getPOS(i);
			int nbrPos = 0;
			int nbrNeg = 0;
			for (int j = 0; j < tokens.size(); j++) {
				WordPolarity wp = wpc.polarity(tokens.get(j), poss.get(j));
				if (wp == null)
					continue;
				if (wp.isPositive())
					nbrPos++;
				if (wp.isNegative())
					nbrNeg++;
			}
			if (nbrPos == nbrNeg)
				post.getSentences().get(i).setEmotion("neu");
			else if (nbrPos > nbrNeg)
				post.getSentences().get(i).setEmotion("pos");
			else
				post.getSentences().get(i).setEmotion("neg");
		}
	}

	@Override
	public void extractFeatures(SentPolarityCorpus spc) {
	}

}
